package com.mxx.common.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @Author itzgyw
 * @Date 2020-01-22
 * @Time 17:37
 * @Description:
 */
@Slf4j
public abstract class CountDownLatchHandle implements ThreadHandle {
    private CountDownLatch countDownLatch;

    public CountDownLatchHandle() {
    }

    @Override
    public void run() {
        try {
            exec();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("CountDownLatchHandle start exception . msg :{}", e.getMessage());
        } finally {
            countDownLatch.countDown();

        }
    }

    protected void setCountDownLatch(CountDownLatch countDownLatch) {
        this.countDownLatch = countDownLatch;
    }

    public abstract void exec() throws Exception;
}
